Imports MySql.Data.MySqlClient
Public Class frmCanDoiTaiKhoan_Ngay
    Private data As DataTable
    Private da As MySqlDataAdapter
    Dim sqlQuery As String

    Private Sub frmCanDoiTaiKhoan_Ngay_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        moduleUtils.setDinhDangVietNam()
        Me.TuNgay_DateTimePicker.Value = moduleUtils.getNgayDauThang(Today.Year, Today.Month)
        Me.DenNgay_DateTimePicker.Value = moduleUtils.getNgayCuoiThang(Today.Year, Today.Month)
    End Sub
    Private Sub btnInBaoCao_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInBaoCao.Click
        Dim myForm As FrmCrCanDoiTaiKhoan_Ngay = New FrmCrCanDoiTaiKhoan_Ngay
        myForm.setThang(CDate(Me.TuNgay_DateTimePicker.Value))
        myForm.setNam(CDate(Me.DenNgay_DateTimePicker.Value))
        myForm.setKey(CDate(Me.DenNgay_DateTimePicker.Value).Year)
        myForm.Show()
    End Sub
    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        Me.Close()
    End Sub
    Private Sub dongtongcong()
        'tinh dong tong cong
        Me.gridTonCDTK.AllowUserToAddRows = True
        Dim vnodau As Double = 0
        Dim vcodau As Double = 0
        Dim vpsno As Double = 0
        Dim vpsco As Double = 0
        Dim vlkno As Double = 0
        Dim vlkco As Double = 0
        Dim vnocuoi As Double = 0
        Dim vcocuoi As Double = 0
        For i As Integer = 0 To Me.gridTonCDTK.Rows.Count - 1
            vnodau = vnodau + Me.gridTonCDTK.Rows.Item(i).Cells.Item(Me.nodau.Index).Value
            vcodau = vcodau + Me.gridTonCDTK.Rows.Item(i).Cells.Item(Me.codau.Index).Value
            vpsno = vpsno + Me.gridTonCDTK.Rows.Item(i).Cells.Item(Me.psno.Index).Value
            vpsco = vpsco + Me.gridTonCDTK.Rows.Item(i).Cells.Item(Me.psco.Index).Value
            vlkno = vlkno + Me.gridTonCDTK.Rows.Item(i).Cells.Item(Me.lkno.Index).Value
            vlkco = vlkco + Me.gridTonCDTK.Rows.Item(i).Cells.Item(Me.lkco.Index).Value
            vnocuoi = vnocuoi + Me.gridTonCDTK.Rows.Item(i).Cells.Item(Me.nocuoi.Index).Value
            vcocuoi = vcocuoi + Me.gridTonCDTK.Rows.Item(i).Cells.Item(Me.cocuoi.Index).Value
        Next
        Me.gridTonCDTK.Item(Me.nodau.Index, Me.gridTonCDTK.Rows.Count - 1).Value = vnodau
        Me.gridTonCDTK.Item(Me.nodau.Index, Me.gridTonCDTK.Rows.Count - 1).Style.ForeColor = Color.Red
        Me.gridTonCDTK.Item(Me.codau.Index, Me.gridTonCDTK.Rows.Count - 1).Value = vcodau
        Me.gridTonCDTK.Item(Me.codau.Index, Me.gridTonCDTK.Rows.Count - 1).Style.ForeColor = Color.Red
        Me.gridTonCDTK.Item(Me.psno.Index, Me.gridTonCDTK.Rows.Count - 1).Value = vpsno
        Me.gridTonCDTK.Item(Me.psno.Index, Me.gridTonCDTK.Rows.Count - 1).Style.ForeColor = Color.Red
        Me.gridTonCDTK.Item(Me.psco.Index, Me.gridTonCDTK.Rows.Count - 1).Value = vpsco
        Me.gridTonCDTK.Item(Me.psco.Index, Me.gridTonCDTK.Rows.Count - 1).Style.ForeColor = Color.Red
        Me.gridTonCDTK.Item(Me.lkno.Index, Me.gridTonCDTK.Rows.Count - 1).Value = vlkno
        Me.gridTonCDTK.Item(Me.lkno.Index, Me.gridTonCDTK.Rows.Count - 1).Style.ForeColor = Color.Red
        Me.gridTonCDTK.Item(Me.lkco.Index, Me.gridTonCDTK.Rows.Count - 1).Value = vlkco
        Me.gridTonCDTK.Item(Me.lkco.Index, Me.gridTonCDTK.Rows.Count - 1).Style.ForeColor = Color.Red
        Me.gridTonCDTK.Item(Me.nocuoi.Index, Me.gridTonCDTK.Rows.Count - 1).Value = vnocuoi
        Me.gridTonCDTK.Item(Me.nocuoi.Index, Me.gridTonCDTK.Rows.Count - 1).Style.ForeColor = Color.Red
        Me.gridTonCDTK.Item(Me.cocuoi.Index, Me.gridTonCDTK.Rows.Count - 1).Value = vcocuoi
        Me.gridTonCDTK.Item(Me.cocuoi.Index, Me.gridTonCDTK.Rows.Count - 1).Style.ForeColor = Color.Red
        'tinh dong tong cong
    End Sub
    Private Sub btnXemCDTK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXemCDTK.Click
        Dim nam As Integer
        nam = CDate(Me.DenNgay_DateTimePicker.Value).Year
        Me.Cursor = Cursors.WaitCursor
        Dim loadTonCDTK As Integer = tonghop.loadTonCDTK_Ngay(CDate(Me.TuNgay_DateTimePicker.Value), CDate(Me.DenNgay_DateTimePicker.Value))
        Me.Cursor = Cursors.Default
        If loadTonCDTK = 1 Then
            Dim sqlQuery = "SELECT * FROM tbl_dot_temp_toncdtk_Ngay  where  recycleid='" & nam & "' and (nodauvn<>0 OR codauvn<>0 OR psnovn<>0 OR pscovn<>0)  ORDER BY ma_taikhoan "
            Me.gridTonCDTK.DataSource = moduleDatabaseConn.GetDataTable(sqlQuery)
        End If
        Me.dongtongcong()
    End Sub
End Class